<?php
$months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
    "Oct", "Nov", "Dec");
ini_set("date.timezone", "Europe/Paris");
$this_day = now();
$pattern_year = "%Y";
$str_year = mdate($pattern_year, $this_day);

for ($i = 0; $i < 12; $i++) {
    $dropdown_data[$i + 1] = $months[$i];
}
for ($i = 0; $i < 31; $i++) {
    $day_data[$i + 1] = $i + 1;
}
for ($i = $str_year; $i > 1900; $i--) {
    $year_data[$i] = $i;
}

$selected_race_setting = array(
        'table_name' => 'doggy_race',
        'key_field' => 'id',
        'value_field' => 'race_name',
    );
$selected_region_setting = array(
        'table_name' => 'animus_sub_region',
        'key_field' => 'id',
        'value_field' => 'name',
    );


if (isset($error))
    echo $error;
?>
<?php
if ($account_data->num_rows() > 0) {
    $account = $account_data->row();
    $date_long = $account->birthday;
    $id = $account->account_id;
    $pattern = "%Y-%m-%d";
    $str_date = mdate($pattern, $date_long);
    $selected_race = $account->race;
    $selected_region = $account->region;
}

echo $erreur;
?>
<?php
$image_path = './doggy_avatar/images/' . $account->avatar;
if ($account->avatar != '') {
    if (file_exists($image_path)) {
        $image_path = base_url() . './doggy_avatar/images/' . $account->avatar;
    } else {
        $image_path = base_url() . 'doggy_avatar/noimage.gif';
    }
} else {
    $image_path = base_url() . 'doggy_avatar/noimage.gif';
}
?>
<div id="nouveaux_membres">
<div class="titre_home" style="text-transform: uppercase;">Information du compte</div>
        <?php echo form_open_multipart(site_url('home/edit_profile') . '/' . $id); ?>
        <table align="center" id="form_profile" cellpadding="10px" cellspacing="0">
            <?php if($this->session->flashdata('msg')==TRUE){?>
            <tr>
                <td colspan="2" style="color: red;"><div id="error"><?php echo $this->session->flashdata('msg'); ?></div></td>
            </tr>
            <?php }?>
            <tr>
                <td>Identifiant</td>
                <td><?php echo $account->account_name; ?></td>
            </tr>
            <tr valign="top">
                    <td colspan="2"><label style="font-weight: bold">Ci-dessous les informations généraux de vos animaux</label></td>
                </tr>
            <tr>
                <td>Nom afficher</td>
                <td><input name="display_name" type="text" value="<?php echo $account->display_name; ?>"/></td>
            </tr>
            <?php if(form_error('display_name')){?>
            <tr>
                <td colspan="2"><?php echo form_error('display_name') ?></td>
            </tr>
            <?php }?>
            <tr>
                <td>Race</td>
                <td><?php echo form_dropdown('race',dropdown_data($selected_race_setting),$selected_race)?></td>
            </tr>
            <tr>
                <td>Région</td>
                <td><?php echo form_dropdown('region',dropdown_data($selected_region_setting),$selected_region)?></td>
            </tr>
            <tr>
                <td>Nom complet</td>
                <td><input name="fullname" size="35" type="text" value="<?php echo $account->fullname; ?>"/></td>
            </tr>
            <?php if(form_error('fullname')){?>
            <tr>
                <td colspan="2"><?php echo form_error('fullname') ?></td>
            </tr>
            <?php }?>
            <tr>
                <td>Couleur</td>
                <td><input name="color" type="text" value="<?php echo $account->color; ?>"/></td>
                <td><?php echo form_error('color') ?><td>
            </tr>
            <?php if(form_error('color')){?>
            <tr>
                <td colspan="2"><?php echo form_error('color') ?></td>
            </tr>
            <?php }?>
            <tr>
                <td rowspan="2">Image du profile</td>
                <td><img width="150" height="100" src="<?php echo $image_path; ?>"></td>
            </tr>
            <tr>
                <td><input name="userfile" id="userfile" type="file" size="25"/></td>
            </tr>
            <tr>
                <td>Addresse</td>
                <td><input name="address" type="text" value="<?php echo $account->address; ?>"/></td>
                <td><?php echo form_error('address') ?><td>
            </tr>
            <?php if(form_error('address')){?>
            <tr>
                <td colspan="2"><?php echo form_error('address') ?></td>
            </tr>
            <?php }?>
            <tr>
                <td>Sex</td>
                <td>
                    <?php
                    $gender = $account->sex;
                    $male = array(
                        'name' => 'gender',
                        'id' => 'rad_male',
                        'value' => 'm',
                        'checked' => $gender == 'm' ? TRUE : FALSE,
                        'style' => 'margin:10px',
                    );
                    $female = array(
                        'name' => 'gender',
                        'id' => 'rad_female',
                        'value' => 'f',
                        'checked' => $gender == 'f' ? TRUE : FALSE,
                        'style' => 'margin:10px',
                    );

                    echo 'Masculin' . form_radio($male);
                    echo 'Féminin' . form_radio($female, 'Female');
                    ?>
                </td>
            </tr>
            <tr>
                <td><label for="birthday">Date de naissance</label></td>
                <td>
                    D : <?php echo form_dropdown('birth_date', $day_data, get_date_part($str_date, 'day'), 'id="day"'); ?>
                    M : <?php echo form_dropdown('birth_month', $dropdown_data, get_date_part($str_date, 'month'), 'id="month"'); ?>
                    A : <?php echo form_dropdown('birth_year', $year_data, get_date_part($str_date, 'year'), 'id="year"'); ?>
                </td>
            </tr>
            <tr>
                <td>Status</td>
                <td><input name="mind_status" type="text" value="<?php echo $account->mind_status; ?>"/></td>
            </tr>
            <tr>
                <td>Description</td>
                <td><input name="self_description" type="text" value="<?php echo $account->self_description; ?>"/></td>
            </tr>
            <tr>
                <td><input type="submit" name="submit" value="Enregistrer"/></td>
            </tr>
        </table>
    <?php echo form_close() ?>

</div>
